package com.vtuzx.kingdee.xqc_api.service;

import com.vtuzx.core.VtuzxException;
import com.vtuzx.core.bean.dto.VtuzxMap;
import com.vtuzx.core.bean.dto.VtuzxToken;
import com.vtuzx.kingdee.xqc_core.bean.xqc.BillMaterial;
import com.vtuzx.kingdee.xqc_core.constant.BillEvent;
import com.vtuzx.kingdee.xqc_core.constant.BillType;
import com.vtuzx.web.bean.VtuzxDownloadBean;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Criteria;

import java.io.File;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

/**
 * 库存服务
 */
public interface IXqcInventoryService {

    /**
     * 获取用户库存物料箱号
     *
     * @param stockNo 仓库编码
     * @param boxNo 箱号
     * @return 用户库存物料箱号
     */
    default VtuzxMap getMaterialBox(String stockNo, String boxNo) throws VtuzxException {
        return getMaterialBox(stockNo, "", boxNo);
    }

    /**
     * 获取用户库存物料箱号
     *
     * @param stockNo 仓库编码
     * @param boxNo 箱号
     * @return 用户库存物料箱号
     */
    VtuzxMap getMaterialBox(String stockNo, String locationNo, String boxNo) throws VtuzxException;

    /**
     * 即时库存入库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param stockNo 仓库编码
     * @param billNo 单据号
     * @param billMaterialList 单据物料详细
     */
    void addInventory(ObjectId _userId, String userName, BillEvent event, BillType billType, String stockNo, String billNo, List<BillMaterial> billMaterialList) throws VtuzxException;

    /**
     * 即时库存批量入库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param billNo 单据号
     * @param billMaterialList 单据物料详细
     */
    void addInventory(ObjectId _userId, String userName, BillEvent event, BillType billType, String billNo, List<BillMaterial> billMaterialList) throws VtuzxException;

    /**
     * 即时库存批量入库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param billNo 单据号
     * @param billMaterialList 单据物料详细
     */
    void addInventoryTran(ObjectId _userId, String userName, BillEvent event, BillType billType, String billNo, List<BillMaterial> billMaterialList) throws VtuzxException;

    /**
     * 即时库存出库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param stockNo 仓库编码
     * @param billNo 单据号
     * @param boxList 箱号详细
     */
    void reduceInventory(ObjectId _userId, String userName, BillEvent event, BillType billType, String stockNo, String billNo, List<String> boxList, List<VtuzxMap> bcBoxList) throws VtuzxException;

    /**
     * 即时库存出库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param stockNo 仓库编码
     * @param billNo 单据号
     * @param boxList 箱号详细
     */
    void reduceInventory(ObjectId _userId, String userName, BillEvent event, BillType billType, String stockNo, String billNo, List<String> boxList, List<VtuzxMap> bcBoxList, List<Document> zsBoxList) throws VtuzxException;

    /**
     * 即时库存批量出库
     *
     * @param _userId 用户ID
     * @param userName 用户名
     * @param event 单据动作
     * @param billType 单据类型
     * @param billNo 单据号
     * @param boxList 箱号详细
     */
    void reduceInventory(ObjectId _userId, String userName, BillEvent event, BillType billType, String billNo, List<String> boxList, List<VtuzxMap> bcBoxList) throws VtuzxException;

    /**
     * 查询即时库存列表
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxMap getInventory(VtuzxToken token, Map<String, Object> param);

    /**
     * 下载即时库存列表
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxDownloadBean downloadInventory(VtuzxToken token, Map<String, Object> param) throws Exception;

    /**
     * 下载即时库存列表托盘
     * @param token
     * @param param
     * @return
     */
    VtuzxMap downloadInventoryTray(VtuzxToken token, Map<String, Object> param) throws Exception;

    /**
     * 下载即时库存列表(总量)
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxDownloadBean downloadInventoryTotal(VtuzxToken token, Map<String, Object> param) throws Exception;

    /**
     * 下载即时库存列表(带箱号)
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxDownloadBean downloadInventoryDetail(VtuzxToken token, Map<String, Object> param) throws Exception;

    /**
     * 查询即时库存详细列表
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxMap getInventoryDetail(VtuzxToken token, Map<String, Object> param);


    /**
     * 根据RFID从即时库存单中获取物料批量入库
     * @param rfidList RFID列表
     * @return 采购收货的物料信息
     */
    default Object getMaterialByRfidInStock(List<String> rfidList, String stockNo) {
        return getMaterialByRfidInStock(rfidList, stockNo, "");
    }

    /**
     * 根据RFID从即时库存单中获取物料批量入库
     * @param rfidList RFID列表
     * @return 采购收货的物料信息
     */
    Object getMaterialByRfidInStock(List<String> rfidList, String stockNo, String locationNo);


    VtuzxMap getBatchAndExpMaterialList(String batchNo, String materialNo, String stockNo, int exp);

    void saveBatchAndExpBill(ObjectId _userId, String name, List<Map<String, Object>> boxList) throws VtuzxException;

    VtuzxMap createBatchAndExpBill(ObjectId userId, String name, String updateBatchNo, int updateExp, List<Map<String, Object>> selectMaterialList) throws VtuzxException;

    VtuzxMap auditBatchAndExpBill(ObjectId _userId, String name, String billNo) throws VtuzxException;

    VtuzxMap unauditBatchAndExpBill(ObjectId userId, String name, String billNo) throws VtuzxException;

    VtuzxMap getBatchAndExpMaterialTempList(ObjectId userId, String name);

    VtuzxMap getBatchAndExpMaterialTempBoxList(ObjectId userId, String name, String id);

    void deleteBillBatchAndExp(ObjectId userId, String name, Map<String, Object> param);

    void deleteMaterialBatchAndExp(ObjectId userId, String name, Map<String, Object> param);

    void deleteBoxBatchAndExp(ObjectId userId, String name, Map<String, Object> param);

    VtuzxMap getBatchAndExpList(ObjectId userId, String name, Map<String, Object> param);

    VtuzxMap getBatchAndExpData(ObjectId userId, String name, String billNo);

    VtuzxMap getInventoryBatch(ObjectId userId, String name, String key);

    VtuzxMap getInventoryBaocai(ObjectId userId, String name, String key, String stockNo);

    VtuzxMap getMaterialSummaryList(ObjectId userId, String name, Map<String, Object> param);

    VtuzxMap getMaterialSummaryDetailList(ObjectId userId, String name, Map<String, Object> param);


    List<VtuzxMap> changeIterator(Iterator<Document> innerIterator);
    /**
     * 下载物料台账报表
     * @param token token
     * @param param 入参
     * @return 查询结果
     */
    VtuzxDownloadBean downloadMaterialSummary(VtuzxToken token, Map<String, Object> param) throws Exception;

    VtuzxDownloadBean downloadMaterialSummaryDetail(VtuzxToken token, Map<String, Object> param) throws Exception;


    double getOneOpening(String materialNo,String stockNo,String createTime,String batchNo);

    /**
     * 查询全部出库单
     */
    VtuzxMap getAllOutStockBill(ObjectId userId, String name, String billNo, String materialNo, String billType, List<String> createTime, int pageIndex, int pageSize) throws VtuzxException;

    /**
     * 手动出库
     * @param userId
     * @param name
     * @param param
     */
    void handOutStock(ObjectId userId, String name, Map<String, Object> param) throws VtuzxException;

    void syncInventory(String name,ObjectId userId) throws Exception;

    //下载箱号和唯一码到excle
    VtuzxDownloadBean downloadInventorySerial(VtuzxToken token, Map<String, Object> param)throws Exception;

    void serialSaleOut(ObjectId _userId, String name) throws Exception;

    /**
     * 修改追溯码
     * @param userId
     * @param name
     * @param param
     */
    VtuzxMap changeTraceCode(ObjectId userId, String name, Map<String, Object> param) throws VtuzxException;

    VtuzxMap getDetailByTrace(String traceBackNo) throws VtuzxException;

    void uploadSaleOut(ObjectId userId, String name, File file) throws Exception;

    /**
     * 追溯上查
     * @param userId
     * @param traceBackNo
     * @return
     */
    VtuzxMap getSerialUp(ObjectId userId, String traceBackNo) throws VtuzxException;

    /**
     * 根据物料和批次查询对应吉客云单号以及卖给哪个客户
     * @param token
     * @param param
     * @return
     */
    VtuzxMap getTraceabilityCodeList(VtuzxToken token, Map<String, Object> param);

    /**
     * 获取损耗率的报表
     * @param token
     * @param param
     * @return
     */
    VtuzxMap getLossRoteList(VtuzxToken token, Map<String, Object> param);

    /**
     * 下载损耗率报表
     * @param token
     * @param param
     * @return
     */
    VtuzxDownloadBean downloadLossRoteList(VtuzxToken token, Map<String, Object> param)throws Exception;

    /**
     * 根据批次号上查
     * @param userId
     * @param batchNo
     * @return
     */
    VtuzxMap getBatchNoUp(ObjectId userId, String batchNo) throws Exception;

    VtuzxMap getRegular(VtuzxToken token, Map<String, Object> param);

    /**
     * 导出定时库存
     * @param token
     * @param param
     * @return
     */
    VtuzxDownloadBean downloadRegular(VtuzxToken token, Map<String, Object> param) throws Exception;

    VtuzxMap getInventoryFeiShu(VtuzxToken token, Map<String, Object> param);

    VtuzxMap getSerialTrade(ObjectId userId, String traceBackNo) throws Exception;

    VtuzxDownloadBean downloadSerialTrade(VtuzxToken token, String traceBackNo) throws Exception;
}
